<?php
require_once 'common.inc.php';

$arr = explode("|", rewrite("file.txt", "read")); 
if($action=='show'){

	include_once 'templates/msystem/removeip.htm';

}elseif ($action == "delete") {

	rewrite("file.txt", "delete", $ip);
	adminmsg('删除成功','removeip.inc.php?action=show');

} elseif ($action == "add") {

	include_once 'templates/msystem/removeip.htm';

} elseif ($action == "edit") {
	$va = $ip;
	include_once 'templates/msystem/removeip.htm';
} elseif ($action == "oadd") {

	rewrite("file.txt", "add", $ip, "");
	adminmsg('添加成功','removeip.inc.php?action=show');

} elseif ($action == "oedit") {

	rewrite("file.txt", "edit", $oldip, $ip);
	adminmsg('编辑成功','removeip.inc.php?action=show');
} 

function getcontent($file) {
	$content = fopen($file, "r");
	while (!feof($content)) {
		$str = fgets($content);
	} 
	fclose($content);
	return $str;
} 

function rewrite($filename, $type, $oldstr = "", $newstr = "") {
	$content = getcontent("file.txt");
	if ($type == "read")
		return $content;
	elseif ($type == "delete") {
		$oldstr .= "|";
		$str = str_replace($oldstr, "", $content);
	} elseif ($type == "edit") {
		$str = str_replace($oldstr, $newstr, $content);
	} elseif ($type == "add") {
		$str = $content . $oldstr . "|";
	} 
	$f = fopen($filename, "w+");
	fwrite($f, $str);
	return $str;
} 

?>